package com.yejiarong.influxdb.api.bean.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @author YeJR
 */
@Data
public class SavePointRequest {

    @NotBlank(message = "指标不能为空")
    private String metric;

    @NotEmpty(message = "标签不能为空")
    private Map<String, String> tags = new HashMap<>();

    @NotEmpty(message = "points不能为空")
    private Map<String, Object> points = new HashMap<>();

    @NotNull(message = "时间戳不能为空")
    private String time;

    public SavePointRequest addTag(final String key, final String value) {
        tags.put(key, value);
        return this;
    }

    public SavePointRequest addTags(final Map<String, String> tagsToAdd) {
        tagsToAdd.forEach(this::addTag);
        return this;
    }

    public SavePointRequest addField(final String field, final Object value) {
        points.put(field, value);
        return this;
    }

    public SavePointRequest addFields(final Map<String, Object> fieldsToAdd) {
        fieldsToAdd.forEach(this::addField);
        return this;
    }

}
